package exercise.day10;

public class 继承牛角尖 {

    public static void main(String[] args) {
        Father s = new Son();
        System.out.println(s.x);
        // 请问，之后这两句后，屏幕上是什么输出？
    }
}
// ---------------------------------------------------
class Father {
    int x = 10;

    public Father() {
        this.print(); // 本质上是调用的son的print方法
        this.x = 20; // 而这里是赋给父类的x变量
    }

    public void print() {
        System.out.println("Father.x = " + x);
    }
}
// ---------------------------------------------------
class Son extends Father {
    int x = 30;

    public Son() {
        this.print();
        x = 40;
    }

    public void print() {
        System.out.println("Son.x = " + x);
    }
}

